package net.jjjshop.common.mapper.lbt;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.jjjshop.common.entity.lbt.LbLineUp;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;

/**
 * 公排

 */
@Mapper
public interface LbLineUpMapper extends BaseMapper<LbLineUp> {

    @Select("SELECT * from lb_line_up WHERE id in(\n" +
            "SELECT b.id from (\n" +
            "select id,COUNT(uid) num from lb_line_up WHERE `status` =0 GROUP BY uid\n" +
            ") b ORDER BY b.num DESC  \n" +
            ") LIMIT 1")
    LbLineUp autoOrderUp();

    @Select("SELECT COUNT(*) num from lb_line_up WHERE `status`=0  and create_time <= #{time}")
    Integer gpNum(@Param("time")Date time,@Param("pid")Integer pid);

    Integer getCount(LbLineUp lbLineUp);

    /**
     * 查询用户在公排数量
     * @return
     */
    @Select("SELECT COUNT(*) from lb_line_up WHERE uid =#{uid}  and  (`status`=1 or `status`=0)")
    Integer gpNum2(@Param("uid") Integer uid,@Param("shopId") Integer shopId);


    @Select("SELECT  COUNT(*) from lb_line_up")
    Integer getLineNum(Integer pid);
}
